<template>
  <div>
    <el-collapse value="common">
      <el-collapse-item title="公共配置" name="common">
        <el-form :model="widget.UI.data" label-width="80px" size="mini" class="pad-lft-rgt-10">
          <el-row :gutter="10">
            <el-col :span="24">
              <el-form-item label="布局方式">
                <el-select v-model="widget.UI.data.layout" placeholder="请选择布局方式" class="width-100"  @change="directionChange">
                  <el-option label="纵向" value="vertical"></el-option>
                  <el-option label="横向" value="horizontal"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="默认颜色">
                <PopoverColor :colorValue="widget.UI.data.trackColor">
                  <CustomColorPicker v-model="widget.UI.data.trackColor" show-alpha></CustomColorPicker>
                </PopoverColor>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="选中颜色">
                <PopoverColor :colorValue="widget.UI.data.valueColor">
                  <CustomColorPicker v-model="widget.UI.data.valueColor" show-alpha></CustomColorPicker>
                </PopoverColor>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="最小值">
                <el-input-number
	                v-model="widget.UI.data.minLimit"
	                :max="widget.UI.data.maxLimit"
	                controls-position="right"
	                placeholder="请设置最小值"
	                class="width-100"
	                @change="(val)=>widgetChange(val,'value')">
                </el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="最大值">
                <el-input-number
	                v-model="widget.UI.data.maxLimit"
	                :min="widget.UI.data.minLimit"
	                controls-position="right"
	                placeholder="请设置最大值"
	                class="width-100">
                </el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="分割总份数">
                <el-input-number v-model="widget.UI.data.divisions" controls-position="right" placeholder="请设置分割总份数"
                                 class="width-100">
                </el-input-number>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-collapse-item>
    </el-collapse>
  </div>
</template>

<script>
  import CustomColorPicker from '@/components/IDE/colorPicker/Color.vue';
  import {WidgetSlider} from "@/modules/IDE/widget/atom/widgetSlider";
  import PopoverColor from '@/components/IDE/colorPicker/Popovers.vue';
  import {deepCopy} from "@/utils";
  import {WidgetFactory} from "@/modules/IDE/widgetFactory";

  export default {
    name: 'SliderSpec',
    components: {
      CustomColorPicker, PopoverColor
    },
    props: {
      widget: {
        type: WidgetSlider,
        default: () => {
          return {};
        }
      }
    },
    computed: {
      state() {
        return this.widget.getCurrentState();
      },
    },
    data() {
      return {
      }
    },
    methods:{
      directionChange(val) {
        let rect = deepCopy(this.widget.rect)
        this.widget.rect.width = rect.height
        this.widget.rect.height = rect.width
      },
      widgetChange(val,category) {
          const {ports = {}} = this.widget;
          const {values = []} = ports;
          const visiblePort = values.find(val => val.key === category) || {};
          visiblePort.value = val;
      },
    }
  };
</script>

<style scoped></style>
